package com.xinqing.test.LetCode;

import java.util.Stack;

/**
 * @Author:CHQ
 * @Date:2021/7/21 14:01
 * @Description
 */
public class Stack2Queue {
    public static void main(String args[]){
       MyQueue queue=new MyQueue();
       queue.push(1);
       queue.push(2);
       System.out.println(queue.pop());
       System.out.println(queue.empty());
    }
}

class MyQueue{
    Stack<Integer> a;
    Stack<Integer> b;
    public MyQueue(){
        a=new Stack<>();
        b=new Stack<>();
    }

    public void push(int val){
        a.push(val);
    }

    public int pop(){
        if(b.isEmpty()){
            while(!a.isEmpty()){
                b.push(a.pop());
            }
        }
        return b.pop();
    }

    public int peek(){
        if(b.isEmpty()){
            while(!a.isEmpty()){
                b.push(a.pop());
            }
        }
        return b.peek();
    }
    public boolean empty(){
        return a.isEmpty() && b.isEmpty();
    }
}
